package com.example.shushiyunsst.fragment.main.transaction.child.kline_chart

import android.os.Bundle
import android.view.View
import androidx.drawerlayout.widget.DrawerLayout
import com.example.library_common.base.LazyFragment
import com.example.shushiyunsst.R
import com.example.shushiyunsst.fragment.main.transaction.bean.TransactionUIInvokeListener
import com.example.shushiyunsst.fragment.main.transaction.child.TransIndexNode
import com.example.shushiyunsst.fragment.main.transaction.child.TransactionMenuFragment

class KlineChartPortraitFragment : LazyFragment(), KlineChartInterface {

    companion object {
        fun newInstance(mTransIndexNode: TransIndexNode?): KlineChartPortraitFragment {
            val args = Bundle()
            args.putSerializable("mTransIndexNode", mTransIndexNode)
            val fragment = KlineChartPortraitFragment()
            fragment.arguments = args
            return fragment
        }
    }

    private var node: TransIndexNode = TransIndexNode()

    private var mKlineChartPortrait = KlineChartPortraitContentFragment.newInstance()

    private var mTransactionMenu = TransactionMenuFragment.newInstance()

    private lateinit var mDrawerLayout: DrawerLayout

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        node = arguments?.getSerializable("mTransIndexNode") as TransIndexNode
    }

    override fun lazyInit() {
        mTransactionMenu.setTransactionUIInvokeListener(this)

        mKlineChartPortrait.setTransactionUIInvokeListener(this)

        loadRootFragment(R.id.mKlineContent, mKlineChartPortrait)
        loadRootFragment(R.id.iconType, mTransactionMenu)
    }

    override fun initView(view: View) {
        mDrawerLayout = view.findViewById(R.id.mDrawerLayout)
    }

    override fun getLayoutId(): Any {
        return R.layout.k_line_chart_portrait_fragment
    }

    override fun onBackPressedSupport(): Boolean {
        if (mDrawerLayout.isOpen) {
            mDrawerLayout.close()
            return true
        }
        pop()
        return true
    }

    override fun toggleDrawerLayout() {
        if (mDrawerLayout.isOpen) {
            mDrawerLayout.close()
        } else {
            mDrawerLayout.open()
        }
    }

    override fun closeDrawerLayout() {
        if (mDrawerLayout.isOpen) {
            mDrawerLayout.close()
        }
    }

    override fun requestIndex() {

    }

    override fun getTransIndexNode(): TransIndexNode {
        return node
    }

    override fun onBackPage() {
        onBackPressedSupport()
    }
}